package com.portalito.jahepi;

import com.portalito.jahepi.R;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class VentanaAlerta implements OnClickListener {
	
	private Dialog dialog;
	private Context context;
	private Button cancelar, confirmar;
	private TextView textView;
	private OnVentanaAlertaListener listener;
	
	public VentanaAlerta(OnVentanaAlertaListener context) {
		this.context = (Context) context;
		this.listener = context;
		
		dialog = new Dialog(this.context);
		dialog.setContentView(R.layout.dialog);
		dialog.setTitle("Aviso");
		dialog.setCancelable(false);
		
		textView = (TextView) dialog.findViewById(R.id.dialogTextView);
		cancelar = (Button) dialog.findViewById(R.id.cancelarButton);
		confirmar = (Button) dialog.findViewById(R.id.confirmarButton);
		
		cancelar.setOnClickListener(this);
		confirmar.setOnClickListener(this);
		
	}
	
	public void setCancelarTexto(CharSequence text) {
		cancelar.setText(text);
	}
	
	public void setConfirmarTexto(CharSequence text) {
		confirmar.setText(text);
	}
	
	public void setTexto(CharSequence text) {
		textView.setText(text);
	}
	
	public void show() {
		dialog.show();
	}
	
	public void dismiss() {
		dialog.dismiss();
	}
	
	public void onClick(View v) {
		if(v == confirmar) {
			listener.onConfirmarVentanaAlerta(this);
		} else if(v == cancelar) {
			listener.onCancelarVentanaAlerta(this);
		}
	}
	
	public interface OnVentanaAlertaListener {
		public void onCancelarVentanaAlerta(VentanaAlerta v);
		public void onConfirmarVentanaAlerta(VentanaAlerta v);
	}
}
